package com.sun.weekend.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.Scroller;

import com.sun.weekend.util.LogUtils;

/**
 * @author sunleilei
 */

public class DragView extends FrameLayout{

    Scroller scroller;
    public DragView(Context context) {
        this(context,null);
    }

    public DragView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public DragView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        scroller = new Scroller(context);
    }

    public void scrollTo(int y) {
        scroller.startScroll(getScrollX(),getScrollY(),0,y,1000);
        invalidate();
    }

    @Override
    public void computeScroll() {
        super.computeScroll();
        if (scroller.computeScrollOffset()) {
            LogUtils.logi(scroller.getCurrX()+"  "+scroller.getCurrY());
            scrollTo(scroller.getCurrX(),scroller.getCurrY());
            postInvalidate();
        }
    }
}
